package com.baoyouqun.controller.back;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.ResourceTypeCreateCmd;
import com.baoyouqun.domain.Query.ResourceTypeQuery;
import com.baoyouqun.domain.UpdateCmd.ResourceTypeUpdateCmd;
import com.baoyouqun.domain.VO.ResourceTypeVO;
import com.baoyouqun.service.ResourceTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/back/resourceType")
@Api(tags = "管理接口")
public class ResourceTypeController {

    @Resource
    private ResourceTypeService resourceTypeService;

    @PostMapping("create")
    @ApiOperation("新增")
    public SingleResponse<ResourceTypeVO> create(ResourceTypeCreateCmd cmd) {
        return resourceTypeService.create(cmd);
    }

    @PutMapping("update")
    @ApiOperation("修改")
    public Response update(ResourceTypeUpdateCmd cmd) {
        return resourceTypeService.update(cmd);
    }

    @DeleteMapping("delete")
    @ApiOperation("根据ID删除")
    public Response delete(String id) {
        StpUtil.checkRole("R010000");
        resourceTypeService.removeById(id);
        return Response.buildSuccess();
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询")
    public SingleResponse<ResourceTypeVO> selectById(String id) {
        return SingleResponse.of(resourceTypeService.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询")
    public PageResponse<ResourceTypeVO> page(ResourceTypeQuery query) {
        IPage<ResourceTypeVO> page = resourceTypeService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}